<template>
<div class="spike-marketing views-container">
    <div class="wlm-table">
        <div class="wlm-table-hearder-btn">
            <router-link tag="span" to="/application/groupsMarketingAdd">
                <el-button size="small" type="primary">添加拼团</el-button>
            </router-link>
        </div>
        <div class="wlm-table-header">
            <el-form :model="tableFormatData.userTable.files" size="small" label-width="85px" class="retail-form" label-position="right">
                <el-form-item label="" class="filter">
                    <el-form-item label="活动名称：">
                        <el-input @keyup.enter.native="filesSerch" v-model="tableFormatData.userTable.files.keyword" placeholder="请输入活动名称" style="width:160px;"></el-input>
                    </el-form-item>
                    <el-form-item label="活动时间：">
                        <el-date-picker v-model="tableFormatData.userTable.files.time" value-format="timestamp" type="datetimerange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']">
                        </el-date-picker>
                    </el-form-item>
                </el-form-item>
                <el-form-item label="" class="filter-btns">
                    <el-button type="primary" @click="filesSerch">筛选</el-button>
                    <el-button type="text" @click="filesEmpty">清空筛选条件</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div class="wlm-table-content">
            <el-tabs v-model="tableFormatData.userTable.files.state" type="card" @tab-click="filesSerch">
                <el-tab-pane label="全部活动" name="0"></el-tab-pane>
                <el-tab-pane label="进行中" name="1"></el-tab-pane>
                <el-tab-pane label="未开始" name="4"></el-tab-pane>
                <el-tab-pane label="已结束" name="3"></el-tab-pane>
                <el-tab-pane label="已停止" name="2"></el-tab-pane>
            </el-tabs>
            <el-table :ref="tableFormatData.userTable.key" :data="tableFormatData.userTable.tableData" @selection-change="handleSelectionChange" style="width: 100%">
                <!-- <el-table-column type="selection" width="55">
                </el-table-column> -->
                <el-table-column prop="date" label="活动名称" min-width="60">
                    <template slot-scope="scope">
                        <span>{{scope.row.title}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="date" label="活动时间" min-width="60">
                    <template slot-scope="scope">
                        <p style="white-space: nowrap;">开始时间:{{scope.row.stime}}</p>
                        <p style="white-space: nowrap;">结束时间:{{scope.row.etime}}</p>
                    </template>
                </el-table-column>
                <!-- <el-table-column prop="name" label="库存/剩余库存" min-width="48"> -->
                <el-table-column prop="name" label="分配总库存/剩余库存" min-width="48">
                    <template slot-scope="scope">
                        <span>{{scope.row.all_stock}}/{{scope.row.over_stock}}</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="活动状态" min-width="43">
                    <template slot-scope="scope">
                        <span v-if="scope.row.status==1">进行中</span>
                        <span v-if="scope.row.status==2">已暂停</span>
                        <span v-if="scope.row.status==3">已结束</span>
                        <span v-if="scope.row.status==4">未开始</span>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="团购销售额/团购订单数" min-width="48">
                    <template slot-scope="scope">
                        <p class="orders-red">￥{{scope.row.total_price}}</p>
                        <p>&nbsp;&nbsp;{{scope.row.groups_number}}</p>
                    </template>
                </el-table-column>
                <el-table-column prop="name" label="单购销售额/单购订单数" min-width="48">
                    <template slot-scope="scope">
                        <p class="orders-red">￥{{scope.row.along_price}}</p>
                        <p>&nbsp;&nbsp;{{scope.row.along_number}}</p>
                    </template>
                </el-table-column>
                <!-- <el-table-column :render-header="renderHeaderOne"  min-width="45">
                    <template slot-scope="scope">
                        <span>￥{{scope.row.total_price}}</span>
                    </template>
                </el-table-column>
                <el-table-column :render-header="renderHeaderOne"  min-width="45">
                    <template slot-scope="scope">
                        <span>{{scope.row.groups_number}}</span>
                    </template>
                </el-table-column> -->
                <el-table-column label="操作">
                    <template slot-scope="scope">
                        <div class="operation-group">
                            <router-link class="wlm-text" tag="span" :to="{path:'/application/groupsInfoList', query :{ groups_id:scope.row.groups_id}}">
                                <el-button type="text">拼团数据</el-button>
                            </router-link>
                            <div class="btn-line" v-if="scope.row.status == 1 || scope.row.status == 2"></div>
                            <el-button v-if="scope.row.status == 1 || scope.row.status == 2" class="wlm-text" type="text" @click="changeTableItem({ groups_id: scope.row.groups_id },tableFormatData.userTable.change.status,{isWarning: scope.row.status === 1,warning:'确定关闭吗？',cancel:{msg:'已取消关闭',val:{scope:scope,cancelStatus:{key:'status',val:1}}}})">{{scope.row.status==2?'开启':'暂停'}}</el-button>
                            <div class="btn-line"></div>
                            <router-link v-if="scope.row.status==4" class="wlm-text" tag="span" :to="{path:'/application/groupsMarketingAdd', query :{ groups_id:scope.row.groups_id}}">
                                <el-button type="text">编辑</el-button>
                            </router-link>
                            <router-link v-if="scope.row.status==1||scope.row.status==3" class="wlm-text" tag="span" :to="{path:'/application/groupsMarketingAdd', query :{ groups_id:scope.row.groups_id}}">
                                <el-button type="text">编辑</el-button>
                            </router-link>
                            <div class="btn-line"></div>
                            <el-button class="wlm-text" type="text" @click="delTableItem(scope.row.groups_id)">删除</el-button>
                        </div>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination-content flex-row flex-justify-e flex-align-c">
                <!-- <el-row class="pagination-btns">
                    <el-checkbox class="check-all" true-label="1" false-label="0" v-model="tableFormatData.userTable.files.checkall" @change="toggleSelection">全部</el-checkbox>
                    <el-button class="right-8" :disabled="isGroup" size="mini" @click="delTableList">删除</el-button>
                </el-row> -->
                <el-pagination :disabled="!hasTableData" @size-change="listPageChange" @current-change="listPageChange" :current-page.sync="tableFormatData.userTable.pagination.page" :page-sizes="tableFormatData.userTable.pagination.pagesizes" :page-size.sync="tableFormatData.userTable.pagination.list_rows" layout="total, sizes, prev, pager, next, jumper" :total="hasTableData?tableFormatData.userTable.pagination.total : 0">
                </el-pagination>
            </div>
        </div>
    </div>
</div>
</template>

<script>
import {
  getGroupsList,
  delGroups,
  setGroupsStatus
} from '@/api/application'
import mixins from '@/mixins/mixins'
export default {
  mixins: [mixins.getters('Table')],
  name: 'SpikeMarketing',
  components: {
  },
  created() {
  },
  data() {
    return {
      data: [{
        id: 1,
        label: '一级 1',
        children: [{
          id: 4,
          label: '二级 1-1'
        }]
      }, {
        id: 2,
        label: '一级 2',
        children: [{
          id: 5,
          label: '二级 2-1'
        }, {
          id: 6,
          label: '二级 2-2'
        }]
      }, {
        id: 3,
        label: '一级 3',
        children: [{
          id: 7,
          label: '二级 3-1'
        }, {
          id: 8,
          label: '二级 3-2'
        }]
      }],
      defaultProps: {
        children: 'children',
        label: 'label'
      },
      blogTitle: '',
      tableFormatData: {
        current: 'userTable',
        userTable: {
          key: 'userTable',
          api: {
            getList: getGroupsList,
            delList: delGroups
          //   msgConfig: {
          //     del: {
          //       type: 'warning',
          //       msg: '此操作会删除用户的所有数据，名下所有平台内如有正在交易的订单、金额，删除后所产生的纠纷由服务商自身承担 如要删除请慎重操作！！'
          //     }
          //   }
          },
          tableData: [],
          files: {
            keyword: '',
            time: '',
            state: '',
            ids: [],
            checkall: '0',
            Recycle: '1'
          },
          change: {
            status: {
              name: '恢复',
              key: 'status',
              api: setGroupsStatus
            }
          },
          pagination: {
            page: 1,
            list_rows: 10,
            pagesizes: [10, 20, 50],
            total: 0
          }
        }
      }
    }
  },
  methods: {
    handleNodeClick(data) {
      console.log(data)
    },
    renderHeaderOne(h, { column, $index }) {
      const label = {
        4: '总实付金额',
        5: '拼团人数'
      }
      const contentText = {
        4: '拼团用户支付的订单金额（包括没有成团退款金额）',
        5: '实际拼团已经支付的用户数'
      }
      return h('el-popover',
        { props: { placement: 'top', trigger: 'hover', width: '200', content: contentText[$index] } },
        [ // 父节点p，数组装子节点，第一个都是标签名字
          h('el-button', {// 第二个子节点，样式写在style，class名字写在calss上
            slot: 'reference', // slot 名字跟上面一样写
            props: {
              type: 'text'
            },
            style: {
              color: 'rgb(144, 147, 153)',
              fontWeight: '700'
            }
          },
          [
            label[$index], // 第一个节点，是一个跟着变的文字，没有属性
            h('i', {
              class: 'el-icon-question',
              style: { marginLeft: '5px' }
            })// 第二个节点，是i标签icon，设置属性
          ])
        ])
    }
  }
}
</script>

<style lang="scss" scoped>
.spike-marketing {}
</style>
